package com.itm.flujos.vista;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EtchedBorder;

/**
 * Clase que tiene el panel de escritura de colisiones
 * 
 * @author jnovo
 *
 */
public class CFilaDatos extends JPanel implements Comparable<CFilaDatos> {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 2377300960520103050L;
	
	private String clave;
	private String valor;
	private CPanelPrincipal pPal;
	
	private static final Color colorFondoATrans = new Color(225,225,240);
	private static final Color colorFondoBTrans = new Color(225,240,225);
	
	private JPanel panelA = new JPanel();
	private JPanel panelB = new JPanel();
	private JLabel textoA = new JLabel();
	private JLabel textoB = new JLabel();
	private GridBagLayout layoutPanel = new GridBagLayout();
	
	private String nombre = "";
	
	public String getNombre() {
		return nombre;
	}

	public void setNombre(String nombre) {
		this.nombre = nombre;
	}
	
	public CFilaDatos(){
		super();
		this.clave="";
		this.valor="";
		init();
	}
	
	public CFilaDatos(String clave, String valor){
		super();
		this.clave=clave;
		this.valor=valor;
		init();
	}
	
	private void init(){
		
		panelA.setLayout(new GridBagLayout());
		panelB.setLayout(new GridBagLayout());
		setLayout(layoutPanel);
		
		setBorder(new EtchedBorder());

		JPanel _panelRellenoTextoA = new JPanel();
		JPanel _panelRellenoTextoB = new JPanel();
		
		panelA.setBackground(colorFondoATrans);
		panelB.setBackground(colorFondoBTrans);
		_panelRellenoTextoA.setBackground(colorFondoATrans);
		_panelRellenoTextoB.setBackground(colorFondoBTrans);

		panelA.add(textoA, new GridBagConstraints(0, 0, 1, 1, 0.0, 1.0, 
				GridBagConstraints.WEST, GridBagConstraints.BOTH,
				new Insets(0, 0, 0, 0), 0, 0));
		panelA.add(_panelRellenoTextoA, new GridBagConstraints(1, 0, 1, 1, 1.0, 1.0, 
				GridBagConstraints.EAST, GridBagConstraints.BOTH,
				new Insets(0, 0, 0, 0), 0, 0));
		
		panelB.add(_panelRellenoTextoB, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, 
				GridBagConstraints.WEST, GridBagConstraints.BOTH,
				new Insets(0, 0, 0, 0), 0, 0));
		panelB.add(textoB, new GridBagConstraints(1, 0, 1, 1, 0.0, 1.0, 
				GridBagConstraints.EAST, GridBagConstraints.BOTH,
				new Insets(0, 0, 0, 0), 0, 0));
		
		
		String _textoA = this.clave;
		textoA.setText(_textoA);
		textoA.setToolTipText(_textoA);
		_panelRellenoTextoA.setToolTipText(_textoA);
			
		nombre += _textoA ;

		String _textoB = this.valor;//CUtiles.getNombre(datos.getObjetoB());
		textoB.setText(_textoB);
		textoB.setToolTipText(_textoB);
		_panelRellenoTextoB.setToolTipText(_textoB);
			
		nombre += _textoB;
		
		// Config panel
		Dimension _dimPaneles = new Dimension(280,20);
		panelA.setMaximumSize(_dimPaneles);
		panelA.setMinimumSize(_dimPaneles);
		panelA.setPreferredSize(_dimPaneles);
		panelB.setMaximumSize(_dimPaneles);
		panelB.setMinimumSize(_dimPaneles);
		panelB.setPreferredSize(_dimPaneles);
		
		add(panelA, new GridBagConstraints(1, 0, 1, 1, 1.0, 1.0, 
				GridBagConstraints.WEST, GridBagConstraints.BOTH,
				new Insets(0, 0, 0, 0), 0, 0));
		
		add(panelB, new GridBagConstraints(3, 0, 1, 1, 1.0, 1.0, 
				GridBagConstraints.WEST, GridBagConstraints.BOTH,
				new Insets(0, 0, 0, 0), 0, 0));
	}
	
	
	public String getClave() {
		return clave;
	}

	public void setClave(String clave) {
		this.clave = clave;
	}

	public String getValor() {
		return valor;
	}

	public void setValor(String valor) {
		this.valor = valor;
	}

	public CPanelPrincipal getPPal() {
		return pPal;
	}

	public void setPPal(CPanelPrincipal pal) {
		pPal = pal;
	}

	public int compareTo(CFilaDatos o) {
		if (o != null && o.getNombre() != null && !o.getNombre().equals("")){
			return this.clave.compareTo(o.clave);
		}
		return -1;
	}
}
